package cn.yunhe.servlet;

import com.jspsmart.upload.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ProductUpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SmartUpload su=new SmartUpload();
        su.initialize(this.getServletConfig(),req,resp);
        try {
            su.upload();
        } catch (SmartUploadException e) {
            e.printStackTrace();
        }
        Files fs=su.getFiles();//获得文件
        File f = fs.getFile(0);//获得上传的文件
        String fname = f.getFileName();//获得文件名
        try {
            su.save("images/product");//保存位置
        } catch (SmartUploadException e) {
            e.printStackTrace();
        }
        Request req1=su.getRequest();
        int id= Integer.parseInt(req1.getParameter("id"));


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
